package com.yj.provider.controller;

import com.yj.provider.handlerMethodArgument.CustomArgumentPage;
import com.yj.provider.handlerMethodArgument.PageableRequest;
import com.yj.provider.handlerMethodArgument.PageableResponse;
import com.yj.provider.pojo.User;
import com.yj.provider.response.ResultResponse;
import com.yj.provider.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;

@RestController
@Slf4j
public class UserController {

    @Autowired
    UserService userService;

    @GetMapping("/getUserInfo")
    public ResultResponse getUserInfo(){
        List<User> list = userService.findAll();
        HashMap<String, Object> map = new HashMap<>();
        map.put("list",list);
        return ResultResponse.success().data(map).data("name","意见");
    }

    @GetMapping("/list")
    public ResultResponse list(@CustomArgumentPage PageableRequest pageableRequest, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "2") int pageSize)
    {
        List<User> list = userService.findAll();
        PageableResponse<List> response = new PageableResponse<>(page,pageSize,list);
        log.info("分页页数：{}",response.getPage());
        log.info("分页每页大小：{}",response.getPageSize());
        log.info("分页数据：{}",response.getData());
        return ResultResponse.success().data("分页数据：",response.getData());
    }

    @GetMapping("/addUser")
    public ResultResponse addUser(@Valid User user){
        return ResultResponse.success();
    }

}
